import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class SolutionInterview17_9 {
    public int getKthMagicNumber(int k) {
        PriorityQueue<Long> priorityQueue=new PriorityQueue<>();
        priorityQueue.offer(1L);
        Set<Long> set=new HashSet<>();
        set.add(1L);
        for (int i = 0; i < k-1; i++) {
            long t=priorityQueue.poll();
            if (!set.contains(t*3)){
                priorityQueue.offer(t*3);
                set.add(t*3);
            }
            if (!set.contains(t*5)){
                priorityQueue.offer(t*5);
                set.add(t*5);
            }
            if (!set.contains(t*7)){
                priorityQueue.offer(t*7);
                set.add(t*7);
            }
        }
        return (int)(priorityQueue.poll().longValue());
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview17_9().getKthMagicNumber(5));
    }
}
